import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

/// 举报选项枚举
enum VamosReportOption {
  inappropriateContent('Inappropriate Content'),
  hateSpeech('Hate Speech'),
  disturbingContent('Disturbing Content'),
  illegalActivity('Illegal Activity'),
  spamAdvertisement('Spam/Advertisement'),
  otherIssues('Other Issues'),
  blockUser('Block User');

  const VamosReportOption(this.displayName);
  final String displayName;
}

/// 举报对话框
class VamosReportDialog extends StatefulWidget {
  final String title;
  final String? subtitle;
  final List<VamosReportOption> availableOptions;
  final Function(VamosReportOption) onReportSubmitted;

  const VamosReportDialog({
    super.key,
    required this.title,
    this.subtitle,
    this.availableOptions = VamosReportOption.values,
    required this.onReportSubmitted,
  });

  @override
  State<VamosReportDialog> createState() => _VamosReportDialogState();
}

class _VamosReportDialogState extends State<VamosReportDialog> {
  VamosReportOption? _selectedOption;

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      child: Container(
        width: 320.w,
        constraints: BoxConstraints(
          maxHeight: MediaQuery.of(context).size.height * 0.8,
        ),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16.r),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.1),
              blurRadius: 20.r,
              spreadRadius: 0,
              offset: Offset(0, 8.h),
            ),
          ],
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 标题区域
            _buildHeader(),

            // 选项列表
            _buildOptionsList(),

            // 按钮区域
            _buildButtonArea(),
          ],
        ),
      ),
    );
  }

  Widget _buildHeader() {
    return Container(
      padding: EdgeInsets.all(24.w),
      child: Column(
        children: [
          // 标题
          Text(
            widget.title,
            style: TextStyle(
              color: Colors.black,
              fontSize: 18.sp,
              fontFamily:
                  GoogleFonts.notoSansSc(
                    fontWeight: FontWeight.w600,
                  ).fontFamily,
              fontWeight: FontWeight.w600,
            ),
            textAlign: TextAlign.center,
          ),

          // 副标题
          if (widget.subtitle != null) ...[
            SizedBox(height: 8.h),
            Text(
              widget.subtitle!,
              style: TextStyle(
                color: Colors.grey[600],
                fontSize: 14.sp,
                fontFamily:
                    GoogleFonts.notoSansSc(
                      fontWeight: FontWeight.w400,
                    ).fontFamily,
                fontWeight: FontWeight.w400,
              ),
              textAlign: TextAlign.center,
            ),
          ],
        ],
      ),
    );
  }

  Widget _buildOptionsList() {
    return Column(
      children:
          widget.availableOptions.asMap().entries.map((entry) {
            final index = entry.key;
            final option = entry.value;
            final isSelected = _selectedOption == option;

            return Column(
              children: [
                Container(
                  height: 56.h,
                  padding: EdgeInsets.symmetric(horizontal: 16.w),
                  child: Row(
                    children: [
                      // 选项文本
                      Expanded(
                        child: Text(
                          option.displayName,
                          style: TextStyle(
                            color: Colors.black,
                            fontSize: 16.sp,
                            fontFamily:
                                GoogleFonts.notoSansSc(
                                  fontWeight: FontWeight.w400,
                                ).fontFamily,
                            fontWeight: FontWeight.w400,
                          ),
                        ),
                      ),

                      // 选中指示器
                      Container(
                        width: 20.w,
                        height: 20.w,
                        decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          border: Border.all(
                            color:
                                isSelected
                                    ? const Color(0xFF83BE4A)
                                    : Colors.grey[300]!,
                            width: 2.w,
                          ),
                          color:
                              isSelected
                                  ? const Color(0xFF83BE4A)
                                  : Colors.transparent,
                        ),
                        child:
                            isSelected
                                ? Icon(
                                  Icons.check,
                                  color: Colors.white,
                                  size: 12.w,
                                ).center()
                                : null,
                      ),
                    ],
                  ).inkWell(
                    onTap: () {
                      setState(() {
                        _selectedOption = option;
                      });
                    },
                  ),
                ),
                // 分隔线
                if (index < widget.availableOptions.length - 1)
                  Divider(height: 1.h, color: Colors.grey[200]),
              ],
            );
          }).toList(),
    );
  }

  Widget _buildButtonArea() {
    return Container(
      padding: EdgeInsets.all(12.w),
      child: Row(
        children: [
          // 取消按钮
          Expanded(
            child: Container(
              height: 44.h,
              decoration: BoxDecoration(
                color: Colors.grey[100],
                borderRadius: BorderRadius.circular(8.r),
              ),
              child: Text(
                'Cancel',
                style: TextStyle(
                  color: Colors.grey[600],
                  fontSize: 16.sp,
                  fontFamily:
                      GoogleFonts.notoSansSc(
                        fontWeight: FontWeight.w500,
                      ).fontFamily,
                  fontWeight: FontWeight.w500,
                ),
              ).center().inkWell(
                onTap: () {
                  Navigator.of(context).pop();
                },
              ),
            ),
          ),

          SizedBox(width: 12.w),

          // 举报按钮
          Expanded(
            child: Container(
              height: 44.h,
              decoration: BoxDecoration(
                gradient: const LinearGradient(
                  colors: [
                    Color(0xFF83BE4A),
                    Color(0xFFF3E3C6),
                    Color(0xFFFB894E),
                  ],
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                ),
                borderRadius: BorderRadius.circular(8.r),
              ),
              child: Text(
                'Report',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 16.sp,
                  fontFamily:
                      GoogleFonts.notoSansSc(
                        fontWeight: FontWeight.w600,
                      ).fontFamily,
                  fontWeight: FontWeight.w600,
                ),
              ).center().inkWell(
                onTap: _selectedOption != null ? _submitReport : null,
              ),
            ),
          ),
        ],
      ),
    );
  }

  void _submitReport() {
    if (_selectedOption != null) {
      Navigator.of(context).pop();
      widget.onReportSubmitted(_selectedOption!);
    }
  }
}

/// 显示举报对话框的便捷方法
Future<void> showVamosReportDialog({
  required BuildContext context,
  required String title,
  String? subtitle,
  List<VamosReportOption>? availableOptions,
  required Function(VamosReportOption) onReportSubmitted,
}) {
  return showDialog<void>(
    context: context,
    barrierDismissible: true,
    builder: (BuildContext context) {
      return VamosReportDialog(
        title: title,
        subtitle: subtitle,
        availableOptions: availableOptions ?? VamosReportOption.values,
        onReportSubmitted: onReportSubmitted,
      );
    },
  );
}
